<?php
// vim:set expandtab tabstop=3 shiftwidth=3 softtabstop=3 foldclose=all foldmethod=marker:
/**
 * 项目：   5anet
 * 文件：   class/album/ShowDetail.class.php
 *
 * 显示相册详细
 *
 * PHP Version 5
 *
 * @package:   class.album
 * @author:    Mike.G Chinese Name: 黄叶 <hylinux@gmail.com>
 * @license:   http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1 
 * @copyright: www.5anet.com
 * @version:   $Id: $
 * @date:      $Date: $
 */

include_once CLASS_PATH.'main/BaseAction.class.php';

//包含相册的工具表
include_once CLASS_PATH.'album/AlbumUtil.class.php';
include_once CLASS_PATH.'user/UserUtil.class.php';




class ShowDetail extends BaseAction {
   /**
    * 数据库的连接
    */
   private $db;


   /**
    * 构造函数
    * @param:  NULL
    * @return: NULL
    * @access: public
    */
   public function __construct() {
      $this->db = $this->getDB();
   }


   /**
    * 显示相册详细
    * @param:  NULL
    * @return: NULL
    * @access: public
    */
   public function run() {
      //取得相册的id
      $id = $this->getParameterFromGET('id');
      
      if ( !$id ) {
         $this->AlertAndBack('没有指定需要查看的相片');
         return;
      }

      if ( !AlbumUtil::isAlbumExists($this->db, $id) ) {
         $this->AlertAndBack('需要查看的相片不存在。');
         return;
      }

      //更新用户查看的次数
      $update = 'update album set clicks=clicks+1 where id=?';
      $sth = $this->db->prepare($update);
      $this->db->Execute($sth, array($id));


      //取得查看相片的信息
      $album_info = AlbumUtil::getPhotoInfo($this->db, $id);

      $smarty = $this->getSmarty();

      //替代变量
      $smarty->assign('album_id', $album_info['id']);
      $smarty->assign('album_name', $album_info['name']);
      $smarty->assign('album_browser_number', $album_info['clicks']);
      $smarty->assign('album_img_path', $album_info['n_path']);
      $smarty->assign('album_normal_path', $album_info['image_path']);
      $smarty->assign('album_score', $album_info['rates']);
      $smarty->assign('album_size', $album_info['size']);
      $smarty->assign('album_description', $album_info['description']);
      $smarty->assign('user_id', $album_info['user_id']);
      $smarty->assign('album_user_name', UserUtil::getUserNameById($this->db, $album_info['user_id']));
      $smarty->assign('dir_id', $album_info['dir_id']);
      $smarty->assign('dir_name', AlbumUtil::getDirName($this->db, $album_info['dir_id']));

      //取得相册的评论
      $photo_comment = AlbumUtil::getPhotoComment($this->db, $id);

      $smarty->assign('comment', $photo_comment);

      //为SEO
      $smarty->assign('clone_title', $album_info['name'].'/相片查看/5anet.com' );
      $smarty->assign('header_meta_content', $album_info['name'].'/'.
         ' 5anet.com'); 





      $smarty->display('showalbumdetail.tmpl');

   }

}

?>
